package com.test.daily.leetcode.y2022.m07.day0723.v01;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/7/23 下午 04:00
 * @version: 1.0
 */
public class Solution {
    public static class Time{
        int start;
        int end;
        public Time(int start, int end){
            this.start = start;
            this.end = end;
        }
    }
    public static int bestRange(Time[] arr){
        return process(arr, 0, 0);
    }
    public static int process(Time[] arr, int done, int timeLine){
        if(arr.length == 0){
            return done;
        }
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i].start >= timeLine){
                max = Math.max(max, process(copyButExcept(arr, i), done + 1, arr[i].end));
            }
        }
        return max;
    }

    public static Time[] copyButExcept(Time[] arr, int i){
        Time[] help = new Time[arr.length - 1];
        int j =0;
        for(int k = 0; k < arr.length; i++){
            if(k != i){
                help[j++] = arr[k];
            }
        }
        return help;
    }

    public static class TimeComparator implements Comparator<Time> {

        @Override
        public int compare(Time o1, Time o2) {
            return o1.end - o2.end;
        }
    }
    public static int bestRange2(Time[] arr){
        Arrays.sort(arr, new TimeComparator());
        int count = 0, timeLine = 0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i].start > timeLine){
                count++;
                timeLine = arr[i].end;
            }
        }
        return count;
    }
}
